package com.yunzheng.studyLeaveSystem.modules.admin.show.condition.servlet;

import com.alibaba.fastjson.JSON;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.entity.adjuster;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.service.AdjustServiceImpl;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/30/10:53
 * @Description:将当天的数据传递到前端
 */
@WebServlet(name = "condition AdjustServlet",value = "/condition_AdjustServlet")
public class DayAdjustServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdjustServiceImpl adjustService = new AdjustServiceImpl();
        List<adjuster> usersList;
        try {
            usersList = adjustService.showDay();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        //JSON输出
        ResponseWrapper responseWrapper = ResponseWrapper.Success(usersList);
        String s = JSON.toJSONString(responseWrapper);
        PrintWriter writer = response.getWriter();
        writer.println(s);
        System.out.println(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
